import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import ViewUI from 'view-design';
Vue.use(ViewUI);

Vue.use(VueRouter)

//配置LoadingBar
ViewUI.LoadingBar.config({
    color: '#5cb85c'
})

const routes = [{
    path: '/',
    name: 'Home',
    meta: { title: '首页' },
    component: Home
}, {
    path: '/cart',
    meta: { title: '试题车' },
    component: () =>
        import ('@/views/Cart')
}, {
    path: '/chart',
    meta: { title: '图表案例' },
    component: () =>
        import ('@/views/Chart')
}, {
    path: '*',
    meta: { title: "404-页面不存在" },
    component: () =>
        import ('@/views/Error/E404')
}]

const router = new VueRouter({
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    }
    ViewUI.LoadingBar.start();
    next()
})

router.afterEach(() => {
    ViewUI.LoadingBar.finish();
});

export default router